import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);
const store = new Vuex.Store({
    state: {
        planAddStepPool:[],
        addPlanType:'',
        headShow:true,
        users:null,
        slectShop_key:'',
        headerNavActive:null
    },
    getters:{
        users(state){
            if(!state.users){
                state.users = JSON.parse(sessionStorage.getItem('users'))
            } 
            return state.users
        },
        selectShop_key(state){
            if(!state.selectShop_key){
                state.selectShop_key = sessionStorage.getItem('selectShop_key');
            } 
            return state.selectShop_key
        },
        headerNavActive(state){
            if(!state.headerNavActive){
                state.headerNavActive = sessionStorage.getItem('headerNavActive');
            } 
            return state.headerNavActive
        }
    },
    mutations: {
        setAddPlanType(state,type){
        	state.addPlanType=type;
        },
        setHeadShow(state,n){
            state.headShow=n;
        },
        setUsers(state,n){
            let obj={
                id:n.id,
                realname:n.realname,
                status:n.status,
                token:n.token,
                username:n.username
            };
            sessionStorage.setItem("users",JSON.stringify(obj));
            state.users=obj;
        },
        signOut(state,n){
            sessionStorage.removeItem("users");
            state.users=null;
            sessionStorage.removeItem("selectShop_key",n);
            state.selectShop_key='';
            sessionStorage.removeItem('headerNavActive');
            state.headerNavActive=null;
        },
        setSelectShop_key(state,n){
            sessionStorage.setItem("selectShop_key",n);
            state.selectShop_key=n;
        },
        setPlanStepPool(state,n){
            if(state.planAddStepPool.findIndex((value)=>{n==value})!=-1){
                 return;
            };
            state.planAddStepPool.push(n);
        },
        clearPlanStepPool(state,n){
            state.planAddStepPool=[];
        },
        setHeaderNavActive(state,n){
            sessionStorage.setItem("headerNavActive",n);
            state.headerNavActive=n;
        }
    },
    actions: {

    }
});

export default store;
